library(ggplot2)
#读取数据
try({
  setwd("./qweqwe/")
})
mydata <- read.table(file = 'Untitled', sep = '\t', header = TRUE)

#数据转置
library(reshape2)
mydata<-melt(mydata,id.vars='Phylum')
#设置新罗马字体
windowsFonts(A=windowsFont("Times New Roman"),
             B=windowsFont("Arial"))
#定义X轴的顺序
mydata$treat <- factor(mydata$variable,
                       levels = c("论文","今年", "一定","接收","全是", "TOP"))#绘图
p1 <- ggplot(mydata,aes(variable, value),position="stack") +
  scale_x_discrete(limits=c("论文","今年", "一定","接收","全是", "TOP"))+
  geom_bar(aes(fill = Phylum), stat = "identity",color="black",size=0.4,
           position = "fill", width = 0.6,data=mydata)+
  scale_fill_manual(values=c("#56B4E9",'gray', '#CCEBC5', '#BC80BD', '#FCCDE5', 
                             '#B3DE69', '#FDB462', '#80B1D3', '#FB8072',
                             '#BEBADA', '#FFFFB3', '#8DD3C7'))+
  theme(
    axis.title=element_text(size=15,face="plain",color="black"),
    axis.text = element_text(size=15,face="plain",color="black"),
    legend.title=element_text(size=15,face="plain",color="black"),
    legend.position = "right",
    panel.background = element_blank(), 
    axis.line = element_line(colour = "black", size = 0.4))+theme_bw()+
  theme(text=element_text(family="A",size=20))+
  theme(axis.ticks.length=unit(-0.25, "cm"), 
        axis.text.x = element_text(margin=unit(c(0.5,0.5,0.5,0.5), "cm")), 
        axis.text.y = element_text(margin=unit(c(0.5,0.5,0.5,0.5), "cm")) )
p1

p2 <- ggplot(mydata,aes(variable, value),position="stack") +
  scale_x_discrete(limits=c("论文","今年", "一定","接收","全是", "TOP"))+
  geom_bar(aes(fill = Phylum), stat = "identity",color="black",size=0.4,
           position = "stack", width = 0.6,data=mydata)+
  scale_fill_manual(values=c("#56B4E9",'gray', '#CCEBC5', '#BC80BD', '#FCCDE5', 
                             '#B3DE69', '#FDB462', '#80B1D3', '#FB8072',
                             '#BEBADA', '#FFFFB3', '#8DD3C7'))+
  theme(
    axis.title=element_text(size=15,face="plain",color="black"),
    axis.text = element_text(size=15,face="plain",color="black"),
    legend.title=element_text(size=15,face="plain",color="black"),
    legend.position = "right",
    panel.background = element_blank(), 
    axis.line = element_line(colour = "black", size = 0.4))+theme_bw()+
  theme(text=element_text(family="A",size=20))+
  theme(axis.ticks.length=unit(-0.25, "cm"), 
        axis.text.x = element_text(margin=unit(c(0.5,0.5,0.5,0.5), "cm")), 
        axis.text.y = element_text(margin=unit(c(0.5,0.5,0.5,0.5), "cm")) )
p2
pall <- p1+p2
Cairo::CairoTIFF(file="djt.tiff", width=20, height=20,dpi=150)
pall
dev.off()


